isPriority(c)
{
	return 
		(c=='(')|
		(c=='+')*2|
		(c=='-')*2|
		(c=='*')*3|
		(c=='/')*3;
}
char str[1010],answer[1010],realans[1010],stack[1010],r;
main(i,dec,op,lparen,rparen,booleanoutput,parenmatching,spaced,spacing,v,w)
{
	for(*str='(';gets(str+1)&&str[1]-'e';realans[w-1]='@',realans[w]=0,booleanoutput|=op|parenmatching,puts(booleanoutput?"syntax error":realans+1))
	{
//		strcpy(str+strlen(str),")");
//		puts(str);
		
		for(i=dec=op=lparen=rparen=parenmatching=v=w=spaced=0,puts(str+1),booleanoutput=strchr(str,')')<strchr(str+1,'('),strcpy(str+strlen(str),")");(r=str[i])&&!booleanoutput;i++)
			if(r-' ')
			{
				booleanoutput|=(r=='+'|r=='-'|r=='*'|r=='/')&&(op|lparen|!(dec^rparen));
				booleanoutput|=(r>='0'&&r<='9')&&(rparen);
				booleanoutput|=(r==')')&(op);
				booleanoutput|=(r=='(')&(rparen);
				dec=r>='0'&&r<='9';
				op=	r=='+'| r=='-'| r=='*'| r=='/';
				lparen=r=='(';
				rparen=r==')';

				if(dec)answer[v++]=r;
				if(!dec)answer[v++]=' ';
				if(lparen)parenmatching++,stack[w++]=r;
				if(rparen)parenmatching--;

				while(rparen&&w&&stack[w-1]-'(')answer[v++]=stack[--w],answer[v++]=' ';
				if(rparen)w--;
				while(op&&w&&isPriority(stack[w-1])>=isPriority(r))answer[v++]=stack[--w],answer[v++]=' ';
				if(op)stack[w++]=r;

				booleanoutput|=(parenmatching<0)|!(dec|op|lparen|rparen);

//				printf("dec:%2d op:%2d lparen:%2d rparen:%2d booleanoutput:%2d parenmatching:%2d\n",dec,op,lparen,rparen,booleanoutput,parenmatching);
			}
		for(i=spaced=w=0;!booleanoutput&&i<v;i++)
		{
			realans[w]=answer[i];
			spacing=answer[i]==' ';
			w+=!(spaced&spacing);
			spaced=spacing;
		}
	}
}
